using CommunityToolkit.Mvvm.Input;
using GetStartedApp.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace GetStartedApp.ViewModel.Page;

public partial class DataGridPageViewModel : ViewModelBase
{
    public DataGridPageViewModel()
    {
        People = new ObservableCollection<Person>(GenerateMockPeopleTable());
    }

    public ObservableCollection<Person> People { get; }

    private IEnumerable<Person> GenerateMockPeopleTable()
    {
        var defaultPeople = new List<Person>()
                            {
                                new Person() { FirstName = "Pat", LastName = "Patterson", EmployeeNumber = 1010, },
                                new Person() { FirstName = "Jean", LastName = "Jones", EmployeeNumber = 973, },
                                new Person() { FirstName = "Terry", LastName = "Tompson", EmployeeNumber = 300, }
                            };

        return defaultPeople;
    }

    /// <summary>
    /// 添加人
    /// </summary>
    [RelayCommand]
    private void AddPeople()
    {
        People.Add(new Person { FirstName = "a", LastName = Guid.NewGuid().ToString().Substring(0, 5), EmployeeNumber = People.Count + 1 });
    }
}